# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=openjfx12
pkgver=12.0.2_p1
_pkgver=${pkgver/_p/+}
pkgrel=1
pkgdesc="Open JavaFX 12"
url="https://hg.openjdk.java.net/openjfx/12-dev/rt"
arch="" # openjdk11 is not yet available on 32 bit arches, gets stuck on others
license="GPL-2.0-with-classpath-exception"
depends="$pkgname-gtk3" # for the virtual openjfx12 package
makedepends="binutils-gold
	cmake
	ninja
	python2
	gperf
	openjdk11-jdk
	alsa-lib-dev
	ffmpeg-dev
	freetype-dev
	gtk+2.0-dev
	gtk+3.0-dev
	icu-dev
	ruby-dev
	sqlite-dev"
subpackages="$pkgname-media:_media
	$pkgname-web:_web
	$pkgname-jmods:_jmods:noarch
	$pkgname-src:_src:noarch
	$pkgname-doc:_doc:noarch
	$pkgname-gtk2:_gtk2
	$pkgname-gtk3:_gtk3
	$pkgname-libs:_libs
	$pkgname-base:_base:noarch
	$pkgname-dev:_dev:noarch"
source="openjfx-$_pkgver.tar.bz2::http://hg.openjdk.java.net/openjfx/12-dev/rt/archive/$_pkgver.tar.bz2
	https://archive.apache.org/dist/ant/binaries/apache-ant-1.8.2-bin.zip

	configure-ant-home.patch
	crosscompile.patch
	disable-architecture-verification.patch
	disable-assembler-on-unsupported-archs.patch
	disable-jit-for-non-x86.patch
	disable-sse2.patch
	disable-webkit-sampling-profiler.patch
	fix-arm32-build.patch
	fix-arm64-build.patch
	gcc-no-error.patch
	use-system-icu.patch
	webcore-linker-flags.patch
	webkit-debug-level.patch"
builddir="$srcdir/rt-$_pkgver"

_ant_home="$srcdir/apache-ant-1.8.2/"
_java_home="/usr/lib/java/openjfx12"

sonameprefix="$pkgname:"
ldpath="$_java_home/lib"

prepare() {
	default_prepare

	# Create build properties
	cat >gradle.properties <<EOF
PROMOTED_BUILD_NUMBER=${_pkgver##*+}
COMPANY_NAME=Alpine
HUDSON_JOB_NAME=abuild
RELEASE_SUFFIX=-alpine
COMPILE_WEBKIT=true
COMPILE_MEDIA=true
# non standard, alpine patched properties
ANT_HOME=$_ant_home
EXTRA_CXXFLAGS=$CXXFLAGS
EXTRA_LDFLAGS=$LDFLAGS
PKG_CONFIG_PATH=$PKG_CONFIG_PATH
PKG_CONFIG_SYSROOT_DIR=$PKG_CONFIG_SYSROOT_DIR
CC=${CC:-gcc}
CXX=${CXX:-g++}
AR=${AR:-ar}
EOF

	# use system provided library for icu
	rm -rf modules/javafx.web/src/main/native/Source/ThirdParty/icu

	# make gradle wrapper executable
	chmod +x ./gradlew
}

build() {
	./gradlew publicExportsStandaloneLinux
}

check() {
	./gradlew check -x :web:test
}

package() {
	mkdir -p "$pkgdir/$_java_home/apps"
	cp -r build/artifacts/javafx-sdk-12*/*                         "$pkgdir/$_java_home"
	cp -r build/artifacts/javafx-jmods-12*/                        "$pkgdir/$_java_home/jmods"
	cp -r build/artifacts/javafx-docs-12*/                         "$pkgdir/$_java_home/api"
}

_jmods() {
	pkgdesc="$pkgdesc (jmods)"
	depends=""
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot"
	mv "$_fromroot/jmods" "$_toroot"
}

_src() {
	pkgdesc="$pkgdesc (src)"
	depends=""
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot/lib"
	mv "$_fromroot/lib/src.zip" "$_toroot/lib/src.zip"
}

_doc() {
	pkgdesc="$pkgdesc (Documentation)"
	depends=""
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot"
	mv "$_fromroot/api" "$_toroot"
}

_gtk2() {
	pkgdesc="$pkgdesc (GTK 2)"
	depends="$pkgname-base"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot/lib"
	mv "$_fromroot/lib/libglassgtk2.so"   "$_toroot/lib"
}

_gtk3() {
	pkgdesc="$pkgdesc (GTK 3)"
	depends="$pkgname-base"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot/lib"
	mv "$_fromroot/lib/libglassgtk3.so"   "$_toroot/lib"
}

_web() {
	pkgdesc="$pkgdesc (web)"
	depends="$pkgname-media"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot/lib"
	mkdir -p "$_toroot/jmods"
	mkdir -p "$_toroot/legal"
	mv \
		"$_fromroot"/lib/libjfxwebkit.so \
		"$_fromroot"/lib/javafx.web.jar \
		"$_toroot/lib"
	mv \
		"$_fromroot"/jmods/javafx.web.jmod \
		"$_toroot/jmods"
	mv \
		"$_fromroot/legal/javafx.web" \
		"$_toroot/legal"
}

_media() {
	pkgdesc="$pkgdesc (media)"
	depends="$pkgname-libs"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot/lib"
	mkdir -p "$_toroot/jmods"
	mkdir -p "$_toroot/legal"

	mv \
		"$_fromroot"/lib/libavplugin.so \
		"$_fromroot"/lib/libgstreamer-lite.so \
		"$_fromroot"/lib/libjfxmedia.so \
		"$_fromroot"/lib/libfxplugins.so \
		"$_fromroot"/lib/javafx.media.jar \
		"$_toroot/lib"
	mv \
		"$_fromroot"/jmods/javafx.media.jmod \
		"$_toroot/jmods"
	mv \
		"$_fromroot/legal/javafx.media" \
		"$_toroot/legal/"
}

_libs() {
	pkgdesc="$pkgdesc (libs)"
	depends=""
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot/lib"
	mv "$_fromroot"/lib/*.so   "$_toroot/lib"
}

_base() {
	pkgdesc="$pkgdesc (base)"
	depends="$pkgname-libs openjdk11-jre"
	_fromroot="$pkgdir/$_java_home"
	_toroot="$subpkgdir/$_java_home"

	mkdir -p "$_toroot"
	mv "$_fromroot/legal" "$_toroot"
	mv "$_fromroot/lib"   "$_toroot"
}

_dev() {
	pkgdesc="$pkgdesc (development)"
	depends="$pkgname-jmods $pkgname-src $pkgname-doc $pkgname-media $pkgname-web"
	mkdir -p "$subpkgdir"
}

sha512sums="35b45abf22922f3bea17a746ccad683f7d408ccd7e3aa27f8775d10fbeec72058c6c5828b4b587a0e8c57dbcdee3e9d465f6ecc414cf78b0b38261d8b0b93f9a  openjfx-12.0.2+1.tar.bz2
b10a420f65dc47b609fd3b7b0fae5b0bd1ddfa6a52cad41bc729c03f7ff82a79092ec81a24cdae363b8b6ec05061267e3cc48a0e14e097d07757bc021cb5619b  apache-ant-1.8.2-bin.zip
0c0c32bc1fcb1766c4149d16b07d5f656300a945208a1df5044c9ad2055c37ea7b348593ef88c529be0ff653daf662fc89b0b0e17acd58d95faafbf76de6b2a4  configure-ant-home.patch
261b5c26c33030caa5350bf1833455f0b80f24a115876b95bba1490a42b9bfde43d36c0887ff15d34cd73e14b89d33633316d4baece480f4cfef2f9e147775f6  crosscompile.patch
33a3e4067347a51f5a8dacd3827e6108aefce1dd6a8b39847b1af4652834ffc36d69622023f18cd6cad73c7a3e2e65b51cf14e57f96bf4152385838f82f99646  disable-architecture-verification.patch
c508a813d8c21151396fd385b6807f757236d0ddb0e33db21368c61c554f845c01326c774eb515a52b098ec51c55f77d1b9c185fba8f6dd0bd4aaf2b32e09880  disable-assembler-on-unsupported-archs.patch
b4a421f68a58d1e1f06344068fa835a07ba55e4ea73a9171fbb2a158c961ac0951ce6f29969f54ae5358f89f8f5284b78bcbf7a2c0727cda82d333d1ed4ca816  disable-jit-for-non-x86.patch
7d8c16f132e31a2caa86391944824dfc74ffdcd689c5429310f1546e66726c800583fb5e2bface1ee663fc4576ded545f6118baac9a0c8b7c67a2d21050ff8c7  disable-sse2.patch
3d443a7216b5f0df3eca1ceb7da9cb973f17d015707cad0203972dee8af1422c3204bd77af36571ded0827a56a21f2f355bb657c1e2ff42da2780667bc8cb995  disable-webkit-sampling-profiler.patch
1c139f90a666638866ce3898d0cd2597f6f6ac9c93eb9cfcf0538c30c63949b9a2a1e9a737d06f6b611cf1b13aef9690c82a14fd6d0ec5f9685418190eefab37  fix-arm32-build.patch
3f7ec35437b94e8773541b8cfbf99c2225540572b0c2ba50a954824aba9ad374085fb1b3532ff7bb53a02346b9b5ef7804acf980016815c56acdf587f6559613  fix-arm64-build.patch
51d4cb484996d62b441ce3ee310703b4e16ad79b4574d936215cb8aea512d5f74511244f0e21d7dc0f56f30469803e3581742444da6db7261b93c60f34ffd91a  gcc-no-error.patch
1ad39f3d53ab52696f8ec6c1039afa494949de1c261dd3c0f9f68372860da2a9c601b09c92b61c9099b399c7589f7f2e313bf93aabaabde0e294ddb7eec60b92  use-system-icu.patch
2b8ec3bae8c93e5b6154988a5a7ac53477b7e86eea00d11cbd5ac1aaa5c87ddeaba239a65423549da29647f839c15d0f25126128f8fa619ea11ae907be646b44  webcore-linker-flags.patch
232aebbd13e2e3291d1ae2bc0df282ade5e861e17fce9aaf378ea930655137a2f3fd6e8b43b1ffbc9c3fcc5b21ec36129bdff1070253d6642162e099b32fc171  webkit-debug-level.patch"
